/**
 * Copyright 2009 by Nathaniel Harward.
 * 
 * This file is part of jtyrant-net.
 * 
 * jtyrant-net is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * jtyrant-net is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with jtyrant-net.  If not, see <http://www.gnu.org/licenses/>
 */
package us.harward.jtn;

/**
 * Thrown when an unsuccessful response code comes back from a Tokyo Tyrant
 * server; contains the code sent back by the server -- see {@link #getCode()}.
 */
public final class FailedCallException extends Exception {

    private static final long serialVersionUID = -4641982033205732748L;

    private final ErrorCode code;

    FailedCallException(final int code) {
	this.code = ErrorCode.lookup(code);
    }

    FailedCallException(final ErrorCode code) {
	this.code = code;
    }

    FailedCallException(final int code, String message) {
	super(message + " [" + ErrorCode.lookup(code) + "]");
	this.code = ErrorCode.lookup(code);
    }

    FailedCallException(final ErrorCode code, String message) {
	super(message + " [" + code + "]");
	this.code = code;
    }

    FailedCallException(final int code, Throwable cause) {
	super(cause);
	this.code = ErrorCode.lookup(code);
    }

    FailedCallException(final ErrorCode code, Throwable cause) {
	super(cause);
	this.code = code;
    }

    FailedCallException(final int code, String message, Throwable cause) {
	super(message + " [" + ErrorCode.lookup(code) + "]", cause);
	this.code = ErrorCode.lookup(code);
    }

    FailedCallException(final ErrorCode code, String message, Throwable cause) {
	super(message + " [" + code + "]", cause);
	this.code = code;
    }

    /**
     * @return the (unsigned) error code sent by the Tokyo Tyrant server.
     */
    public ErrorCode getCode() {
	return code;
    }

}
